

#include "menuscene.h"
#include "armiesscene.h"
#include "resourcemanager.h"
#include "log.h"
#include "messagequeue.h"
#include "gamemanager.h"
#include "gamedatamanager.h"
#include "cocos-ext.h"
#include "goldcoinscene.h"

MenuScene::MenuScene()
{

}

MenuScene::~MenuScene() {
	CCTextureCache::sharedTextureCache()->removeTextureForKey("textures/bg.jpg");
}

bool MenuScene::init() {
	if (!CCScene::init()) {
		return false;
	}

	CCLayer* _layer = CCLayer::create();
	_layer->setContentSize(GM->screenSize);
	addChild(_layer);

	CCSprite* spr = CCSprite::create("textures/bg.jpg");
	CCSize size = spr->getContentSize();
	spr->setAnchorPoint(CCPointZero);
	spr->setPosition(CCPointZero);
	spr->setScaleX(GM->xscale);
	spr->setScaleY(GM->yscale);
	_layer->addChild(spr);

	auto btnPlayGame = RM->makeButton("button/menu_button_0.png", "button/menu_button_1.png", nullptr, this, menu_selector(MenuScene::onPlayGame), _layer);
	btnPlayGame->setPosition(XY_SCALE(800, 200));
	btnPlayGame->setScale(GM->minscale);
	RM->makeButtonLabel("PLAY", 24, btnPlayGame);

	auto btnExit = RM->makeButton("button/menu_button_0.png", "button/menu_button_1.png", nullptr, this, menu_selector(MenuScene::onClose), _layer);
	btnExit->setPosition(XY_SCALE(800,120));
	btnExit->setScale(GM->minscale);
	RM->makeButtonLabel("EXIT", 24, btnExit);

	return true;
}

void MenuScene::onClose(CCObject *sender) {
	CCDirector::sharedDirector()->end();
}

void MenuScene::keyBackClicked() {
	onClose(nullptr);
}

void MenuScene::keyMenuClicked() {

}

void MenuScene::onEnter() {
	CCScene::onEnter();

	CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(this);
}

void MenuScene::onExit() {
	CCScene::onExit();

	CCDirector::sharedDirector()->getKeypadDispatcher()->removeDelegate(this);
}

void MenuScene::onPlayGame(CCObject *sender) {
	ArmiesScene* scene = ArmiesScene::create();
	CCDirector::sharedDirector()->replaceScene(scene);
}
